package com.joysuch.wwyt.attendant.controller;

import com.joysuch.wwyt.attendant.bean.AttendantRecordSearchBean;
import com.joysuch.wwyt.attendant.bean.vo.AttendantRecordDetailVo;
import com.joysuch.wwyt.attendant.entity.AttendantPlanContent;
import com.joysuch.wwyt.attendant.service.AttendantRecordService;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description //TODO
 * @Date 2023/2/15 14:45
 * @Author Leong
 **/
@RestController
@RequestMapping("/attendant/record")
@Api(tags = "跟班记录")
public class AttendantRecordController {

    @Resource
    private AttendantRecordService attendantRecordService;

    @GetMapping("/page")
    @ApiOperation("跟班记录列表")
    public ResultBean page(AttendantRecordSearchBean searchBean) {
        return attendantRecordService.findPage(searchBean);
    }

    @PostMapping("/delete")
    @ApiOperation("删除跟班记录")
    public ResultBean delete(Long id) {
        attendantRecordService.delete(id);
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("/detail")
    @ApiOperation("查看跟班记录详情")
    public ResultBean detail(@RequestParam(value = "id") Long id) {
        AttendantRecordDetailVo bean = attendantRecordService.detail(id);
        return ResultBean.success(bean);
    }

    @GetMapping("/track")
    @ApiOperation("查看跟班轨迹")
    public ResultBean track(@RequestParam(value = "id") Long id) throws IllegalArgumentException {
        return attendantRecordService.track(id);
    }

    @GetMapping("/stay/time")
    @ApiOperation("查询围栏停留时间")
    public ResultBean stay(@RequestParam(value = "id") Long id) {
        String time = attendantRecordService.stay(id);
        return ResultBean.success(time);
    }

    @PostMapping("/update")
    @ApiOperation("修改跟班记录")
    public ResultBean update(@RequestBody List<AttendantPlanContent> list) {
        attendantRecordService.updateRecord(list);
        return ResultBean.defaultSuccessResult();
    }

}
